package com.xy.bioapi.service;

import com.xy.bioapi.entity.Test;
import com.xy.bioapi.enums.ResultEnum;
import com.xy.bioapi.exception.TestException;
import com.xy.bioapi.repository.TestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * 实验数据
 * Created by DELL on 2017/7/11.
 */
@Service
public class TestService{

    @Autowired
    private TestRepository testRepository;

    /**
     * 保存实验数据
     * @param test
     */
    public void saveTest(Test test){
        try{
            testRepository.save(test);
        }catch (Exception e){
            e.printStackTrace();
        }
        /*if(testRepository.findByEquipmentId(test.getEquipmentId()) == null){
            testRepository.save(test);
        }else{
            throw new TestException(ResultEnum.EQUIPMENT_EXISTED);
        }*/
    }

    /**
     * 通过设备ID查询实验数据集合
     * @param equipmentId
     * @return
     */
    public Set<Test> getTestByEquipmentId(Long equipmentId){

        if (equipmentId == null){
            return  null;
//            throw new TestException(ResultEnum.ILLEGAL_EQUIPMENT_ID);
        }else{
            return testRepository.findByEquipmentId(equipmentId);
        }
    }
}
